//
//  BaseViewController.m
//  customer
//
//  Created by Holothurian on 2018/10/19.
//  Copyright © 2018年 yinlong. All rights reserved.
//

#import "BaseViewController.h"

@interface BaseViewController ()

@end

@implementation BaseViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor backGroudColorForView];
    self.automaticallyAdjustsScrollViewInsets = NO;
}

- (void)showLoading {
    MBProgressHUD * hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    hud.mode = MBProgressHUDModeIndeterminate;
    hud.label.text = @"正在努力加载...";
    hud.contentColor = [UIColor whiteColor];
    hud.bezelView.backgroundColor = [UIColor blackColor];
    [self.view addSubview:hud];
    [hud showAnimated:YES];
}

- (void)showLoadingTitle:(NSString*)title{
    MBProgressHUD * hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    hud.mode = MBProgressHUDModeIndeterminate;
    hud.label.text = title;
    hud.contentColor = [UIColor whiteColor];
    hud.bezelView.backgroundColor = [UIColor blackColor];
    [self.view addSubview:hud];
    [hud showAnimated:YES];
}

- (void)showTipWithTitle:(NSString*)title {
    MBProgressHUD * hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    hud.mode = MBProgressHUDModeText;
    hud.label.text = title;
    hud.contentColor = [UIColor whiteColor];
    hud.bezelView.backgroundColor = [UIColor blackColor];
    [self.view addSubview:hud];
    [hud showAnimated:YES];
    [hud hideAnimated:YES afterDelay:1.0f];
}

- (void)showErrorTipWithTitle:(NSString*)title {
    MBProgressHUD * hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    hud.mode = MBProgressHUDModeCustomView;
    hud.label.text = title;
    hud.contentColor = [UIColor whiteColor];
    hud.customView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"closeNet"]];
    hud.bezelView.backgroundColor = [UIColor blackColor];
    [self.view addSubview:hud];
    [hud showAnimated:YES];
    [hud hideAnimated:YES afterDelay:1.0f];
}

- (void)showSuccessWithType:(NSInteger)imageType AndTitle:(NSString *)title{
    MBProgressHUD * hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    hud.mode = MBProgressHUDModeCustomView;
    hud.label.text = title;
    hud.contentColor = [UIColor whiteColor];
    UIImage *image = nil;
    if (imageType == 0) {
        image = [UIImage imageNamed:@"sucessApi"];
    }else{
        image = [UIImage imageNamed:@""];
    }
    hud.customView = [[UIImageView alloc]initWithImage:image];
    hud.bezelView.backgroundColor = [UIColor blackColor];
    [self.view addSubview:hud];
    [hud showAnimated:YES];
    [hud hideAnimated:YES afterDelay:1.0f];
}

- (void)showSubmitSuccessPageWithTitle:(NSString *)tilte Somebody:(NSString *)somebody ButtonTitle:(NSString *)buttonTitle{
    AutoWeakSelf
    UIView *backView = [[UIView alloc]init];
    backView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:backView];
   
    [backView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.view.mas_top).offset(NAVIGATION_BAR_HEIGHT);
        make.left.right.bottom.equalTo(weakSelf.view).offset(0);
    }];
    
    UIImageView *imageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"missionSuccessClock"]];
    imageView.contentMode = UIViewContentModeScaleAspectFit;
    [backView addSubview:imageView];
    imageView.layer.cornerRadius = 60;
    imageView.layer.masksToBounds = YES;
    [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(backView).offset(50);
        make.centerX.equalTo(backView);
        make.size.mas_equalTo(CGSizeMake(120, 120));
    }];
    
    
    UILabel *centerLabel = [[UILabel alloc]init];
    centerLabel.text = [NSString stringWithFormat:@"%@\n\n稍后会有%@，请保持手机畅通！",tilte,somebody];
    centerLabel.textColor = [HSPublic colorWithHexString:@"808080"];
    centerLabel.numberOfLines = 0;
    centerLabel.font = Font(18);
    centerLabel.textAlignment = NSTextAlignmentCenter;
    [backView addSubview:centerLabel];
    [centerLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(imageView.mas_bottom).offset(20);
        make.left.equalTo(backView).offset(30);
        make.right.equalTo(backView).offset(-30);
        make.height.mas_equalTo(100);
    }];
    
    UIButton *checkButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [checkButton setTitle:[buttonTitle isEqualToString:@""]?@"查看预约":buttonTitle forState:UIControlStateNormal];
    [checkButton setTitle:[buttonTitle isEqualToString:@""]?@"查看预约":buttonTitle forState:UIControlStateSelected];
    [checkButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [checkButton setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
    [checkButton setBackgroundColor:[UIColor blackColor]];
    checkButton.layer.cornerRadius = 6;
    checkButton.layer.masksToBounds = YES;
    [backView addSubview:checkButton];
    [checkButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(centerLabel.mas_bottom).offset(60);
        make.left.equalTo(backView).offset(30);
        make.right.equalTo(backView).offset(-30);
        make.height.mas_equalTo(50);
    }];
    [checkButton addTarget:self action:@selector(checkOutAppointment) forControlEvents:UIControlEventTouchUpInside];
}

- (void)checkOutAppointment{
    
}

- (void)hideLoading {
    [MBProgressHUD hideHUDForView:self.view animated:YES];
}

- (void)hideLoadingAfter:(CGFloat)time{
    [UIView animateWithDuration:time animations:^{
        [MBProgressHUD hideHUDForView:self.view animated:YES];
    }];
    
}

- (void)dealloc{
    NSLog(@"%@",[self class]);
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
